package com.example.phototest.Utils;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.RenderedImage;
import java.io.IOException;

public class PhotoUtil {
    public void responseImage(Image image, HttpServletResponse response){
        //设置响应类型，告诉浏览器输出的内容是图片
        response.setContentType("image/jpeg");
        //设置响应头信息，告诉浏览器不用缓冲此内容
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expire", 0);
        try {
            //把内存中的图片通过流动形式输出到客户端
            ImageIO.write((RenderedImage) image, "JPG", response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
